﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Elegant.Telas.Controles;
using System.Xml;
using System.Data;
using Elegant2.Business.Events;

namespace Elegant
{
    class TicketOpenReadFile
    {
 
        #region Leitura de Arquivo TXT  
        /// <summary>
       ///Ler Arquivo Tipo Texto.
       ///E realiza a separação dos caracteres especiais.
       /// </summary>
       /// <param name="filePath">Caminho Do Arquivo a ser Lido</param>
       /// <param name="T">Objeto do tipo Ticket</param>
        public void TicketReadFileTxt(string filePath, Ticket T)
        {
            FileManager fm = new FileManager();
            LogTicketManager ltm = new LogTicketManager();
            fm.openReadFile(filePath);

            while (fm.isEndOfStream() != true)
            {
                string valor = fm.readLine();

                char[] caracter = { ',' };
                string[] result = valor.Split(caracter);

                for (int i = 0; i < result.Length; i++)
                {
                    string teste = result[i];
                    string teste2 = teste.Replace('"', ' ');

                    //Pega o objeto Ticket e acessa o controle ListBox. 
                    T.lstEstados.Items.Add(ltm.putStartProcessLog(teste2));
                }
            }
        }
        #endregion

        #region Leitura de Arquvo XML
        /// <summary>
        /// Realiza a leitura de Arquivo XML.
        /// </summary>
        /// <param name="filePath">Caminho do Arquivo XML a ser lido.</param>
        /// <param name="T">Objeto Ticket</param>
        public void TicketReadFileXml(string filePath, TicketEventDeclaration ticketEvent)
        {
            try
            {
                DataSet dts = new DataSet();
                dts.ReadXml(filePath);
                
                for (int i = 0; i < dts.Tables[0].Rows.Count; i++)
                {
                    Tickets tickets = new Tickets();
                    ticketEvent.TicketStatus("Iniciou e Pegou");
                    dts.Tables[0].Rows[i]["TICKETSTATE"].ToString();
                    dts.Tables[0].Rows[i]["PLATE"].ToString();
                    tickets.Plate = dts.Tables[0].Rows[i]["PLATE"].ToString();
                    dts.Tables[0].Rows[i]["STATE"].ToString();
                    tickets.Estate = dts.Tables[0].Rows[i]["STATE"].ToString();
                    dts.Tables[0].Rows[i]["VEHMAKE"].ToString();
                    tickets.Make = dts.Tables[0].Rows[i]["VEHMAKE"].ToString();
                    dts.Tables[0].Rows[i]["OBS1"].ToString();
                    dts.Tables[0].Rows[i]["OBS2"].ToString();
                    
                    
                }
            }
            catch (Exception ex)
            {
                
            }
           
        }

        #endregion

    }
}
